﻿@model Projectmanagement.Models._Tracel
@{
    var files = ViewBag.files as List<Projectmanagement.Entity.TaskFile>;
}
<script type="text/javascript">
    var fileName = "";

    function UploadProfileImage_OnUpload(e) {

        var id = $("#ID").val();
        var files = e.files;

        // Check the extension of each file and abort the upload if it is not .jpg
        $.each(files, function () {
            fileName = this.name + ',' + fileName;
        });

        $("#TravelFileId").val(fileName);
        e.data = { strImageName: fileName };
    }
    
   
</script>
<fieldset>
    <legend>旅行社</legend>
<table class="noline" style="line-height: 30px; border:1px solid #eee; margin-top:10px;">
    <tr style="line-height: 1px; background:#f1f1f1">
        <td colspan="8">
            <p style="font-weight: bolder">
                联系人</p>
        </td>
    </tr>
    <tr>
        <td align="right">
            @Html.LabelFor(x => x.ComyanyName):
        </td>
        <td>
            @Html.TextBoxFor(x => x.ComyanyName, new { style = "width:165px;" })<br />
            @Html.ValidationMessageFor(x => x.ComyanyName)
        </td>
        <td align="right">
            @Html.LabelFor(x => x.TravelName):
        </td>
        <td>
            @Html.TextBoxFor(x => x.TravelName, new { style = "width:165px;" })<br />
            @Html.ValidationMessageFor(x => x.TravelName)
        </td>
        <td align="right">@Html.LabelFor(x => x.TravelWay):
        </td>
        <td>
            @Html.TextBoxFor(x => x.TravelWay, new { style = "width:165px;" })<br />
        </td>
        <td colspan="2">&nbsp;</td>
    </tr>
    <tr>
        <td align="right">@Html.LabelFor(x => x.City):
        </td>
        <td>
            @Html.DropDownListFor(x => x.City, Model.GetCitySelectListItems(), "请选择......", new { style = "width:165px;" })
        </td>
        <td align="right">@Html.LabelFor(x => x.TravelPost):
        </td>
        <td>
            @Html.TextBoxFor(x => x.TravelPost, new { style = "width:165px;" })<br />
        </td>
        <td align="right">@Html.LabelFor(x => x.TravelOtherWay):
        </td>
        <td>
            @Html.TextBoxFor(x => x.TravelOtherWay, new { style = "width:165px;" })<br />
            @Html.ValidationMessageFor(x => x.TravelOtherWay)
        </td>
        <td colspan="2">&nbsp;</td>
    </tr>
    <tr>
        <td align="right" style="vertical-align:top;">
            @Html.LabelFor(x => x.TravelDesc):
        </td>
        <td colspan="7">
            @Html.TextAreaFor(x => x.TravelDesc, new { rows = "1", style="width: 98%;"})<br />
            @Html.ValidationMessageFor(x => x.TravelDesc)
        </td>
    </tr>
    <tr>
        <td align="right" style="width:80px;">
            <label>文件上传:</label>
        </td>
        <td colspan="7">
            @Html.HiddenFor(m => m.TravelFileId)
            @Html.HiddenFor(m => m.ID)
            @(Html.Telerik().Upload()
                .Name("attachments")
        .Multiple((bool)ViewData["multiple"])
        .Async(async => async
                                    .Save("SaveTravelFile", "Tracel", new { strImageName = Model.TravelFileId })
                                    .Remove("RemoveTravelFile", "Tracel")
            .AutoUpload((bool)ViewData["autoUpload"])

        )
                .ClientEvents(events => events.OnUpload("UploadProfileImage_OnUpload").OnComplete("OnComplete"))
)
        </td>
    </tr>
    <tr>
        <td align="right">
            <label>
                文件下载:</label>
        </td>
        <td colspan="7">
            <ul id="filelist">
            </ul>
        </td>
    </tr>
</table>
</fieldset>
<script type="text/javascript">
    var count = 0;
    function getFile() {

        var id = $("#ID").val();
        var url = "/Tracel/GetFile/";
        $.post(url, { 'ID': id }, function (data) {
            $.each(data, function (i, item) {

                $("#filelist").append(
                '<li id=tf-' + item.ID + '>' +

                 '<a href=' + item.FileUrl + ' target="_blank">' + item.FileName + '</a>' +
                 '<a href="javascript:;" onclick="deletetaskfile(' + item.ID + ')">删除</a>' +
                  '</li>');
            });

        });

    }

    (function () {

        if ((document.readyState && document.readyState == 'complete' && $("#ID").val() != "0") || count == 5) {


            var id = $("#ID").val();
            getFile();
        } else {
            count++;
            setTimeout(arguments.callee, 10);
        }
    })();

    function deletetaskfile(id) {

        var name = $("#tf-" + id).find("a").eq(0).text();
        if (confirm("确定将" + name + "删除吗")) {
            $.ajax({
                url: "/Tracel/deletefile/" + id,
                type: "post",
                dataType: "json",
                success: function (data, status) {

                    if (data == "OK") {
                        $("#tf-" + id).remove();
                    }
                }
            });
        }
    }
</script>
<style>
    .t-upload
    {
        float: left;
    }
    
    .note
    {
        clear: left;
        float: left;
    }
    .noline
    {
        width: 100%;
    }
    .noline, .noline tr, .noline td
    {
        border: 0;
        padding: 2px;
    }
    .tableTd
    {
        width: 120px;
        float: left;
        text-align: left;
    }
</style>
